#include "mainwindow.h"

#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QToolBar>
#include <QDockWidget>
#include <QStatusBar>
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setWindowTitle("测试主窗口");
    resize(600, 480);
    //------添加菜单栏------
    QMenuBar *mBar = menuBar();//该函数会创建一个菜单栏
    setMenuBar(mBar);
    QMenu *fileMenu = mBar->addMenu("文件");
    QMenu *editMenu = mBar->addMenu("编辑");
    QMenu *toolMenu = mBar->addMenu("工具");

    QAction *newAc = new QAction("新建");
    QAction *openAc = new QAction("打开");
    QAction *saveAc = new QAction("保存");

    fileMenu->addAction(newAc);
    fileMenu->addAction(openAc);
    fileMenu->addSeparator();
    fileMenu->addAction(saveAc);

    //------添加工具栏------
    QToolBar *tBar = new QToolBar();
    addToolBar(Qt::TopToolBarArea, tBar);
    tBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);

    tBar->addAction(newAc);
    tBar->addAction(openAc);
    tBar->addSeparator();
    tBar->addAction(saveAc);

    //------添加浮动窗口（铆接部件）------
    QDockWidget *dockWid = new QDockWidget("浮动窗口");
    addDockWidget(Qt::LeftDockWidgetArea, dockWid);

    //------添加中心部件（铆接部件）------
    QPushButton *btn = new QPushButton("中心按钮");
    setCentralWidget(btn);

    //------添加状态栏------
    QStatusBar *sBar = new QStatusBar();
    setStatusBar(sBar);

    QPushButton *btn1 = new QPushButton("按钮1");
    QPushButton *btn2 = new QPushButton("按钮2");
    QPushButton *btn3 = new QPushButton("按钮3");
    sBar->addWidget(btn1);
    sBar->addWidget(btn2);
    sBar->addPermanentWidget(btn3);



}

MainWindow::~MainWindow()
{
}

